package com.kkd.kkdapp.activity;

import com.kkd.kkdapp.R;
import com.kkd.kkdapp.base.BaseActivity;

import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

/**
 * 还款结果
 * 
 * @author mty
 * 
 */
public class RepaymentResultActivity extends BaseActivity implements
		OnClickListener {
	private ImageView icon_img; // 成功或失败图标
	private TextView hint_tv; // 提示语
	private TextView periods_tv; // 期数
	private TextView amount_tv; // 还款金额
	private TextView balance_tv; // 账户余额
	private Button return_bt; // 返回
	private RelativeLayout title_img; // 返回

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_repayment_result);
		initView();
		setListener();
		getMessage();
	}

	public void initView() {
		icon_img = (ImageView) this.findViewById(R.id.icon_img);
		hint_tv = (TextView) this.findViewById(R.id.hint_tv);
		periods_tv = (TextView) this.findViewById(R.id.periods_tv);
		amount_tv = (TextView) this.findViewById(R.id.amount_tv);
		balance_tv = (TextView) this.findViewById(R.id.balance_tv);
		return_bt = (Button) this.findViewById(R.id.return_bt);
		title_img = (RelativeLayout) this.findViewById(R.id.title_img);
	}

	public void setListener() {
		return_bt.setOnClickListener(this);
		title_img.setOnClickListener(this);
	}

	public void getMessage() {
		Intent intent = this.getIntent();
		String desc = intent.getStringExtra("desc");
		hint_tv.setText(desc);
		int bill_num = intent.getIntExtra("bill_num", -1);
		periods_tv.setText("第" + bill_num + "期");
		String unPayMoney = intent.getStringExtra("unPayMoney");
		int mCode = intent.getIntExtra("mCode", -1);
		if (mCode == 0) {
			if (!TextUtils.isEmpty(unPayMoney)) {
				amount_tv.setText(unPayMoney);
			}
			icon_img.setImageResource(R.drawable.repaymentresult_succeed_img);
		} else {
			if (!TextUtils.isEmpty(unPayMoney)) {
				amount_tv.setText("--");
			}
			icon_img.setImageResource(R.drawable.repaymentresult_bedefeated_img);
		}
		String mBalance = intent.getStringExtra("mBalance");
		balance_tv.setText(mBalance);
	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.return_bt:
			finish();
			break;
		case R.id.title_img:
			finish();
			break;
		}
	}

}
